package com.ruoyi.riv.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.DataScope;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.riv.domain.RiverEvent;
import com.ruoyi.riv.service.IRiverEventService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 河流事件Controller
 * 
 * @author ruoyi
 * @date 2024-10-23
 */
@RestController
@RequestMapping("/riv/event")
public class RiverEventController extends BaseController
{
    @Autowired
    private IRiverEventService riverEventService;

    /**
     * 查询河流事件列表
     */
    @PreAuthorize("@ss.hasPermi('riv:event:list')")
    @GetMapping("/list")
    @DataScope(userAlias = "u")
    public TableDataInfo list(RiverEvent riverEvent)
    {
        startPage();
        List<RiverEvent> list = riverEventService.selectRiverEventList(riverEvent);
        return getDataTable(list);
    }

    /**
     * 导出河流事件列表
     */
    @PreAuthorize("@ss.hasPermi('riv:event:export')")
    @Log(title = "河流事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RiverEvent riverEvent)
    {
        List<RiverEvent> list = riverEventService.selectRiverEventList(riverEvent);
        ExcelUtil<RiverEvent> util = new ExcelUtil<RiverEvent>(RiverEvent.class);
        util.exportExcel(response, list, "河流事件数据");
    }

    /**
     * 获取河流事件详细信息
     */
    @PreAuthorize("@ss.hasPermi('riv:event:query')")
    @GetMapping(value = "/{eventId}")
    public AjaxResult getInfo(@PathVariable("eventId") Long eventId)
    {
        return success(riverEventService.selectRiverEventByEventId(eventId));
    }

    /**
     * 新增河流事件
     */
    @PreAuthorize("@ss.hasPermi('riv:event:add')")
    @Log(title = "河流事件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiverEvent riverEvent)
    {
        return toAjax(riverEventService.insertRiverEvent(riverEvent));
    }

    /**
     * 修改河流事件
     */
    @PreAuthorize("@ss.hasPermi('riv:event:edit')")
    @Log(title = "河流事件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiverEvent riverEvent)
    {
        return toAjax(riverEventService.updateRiverEvent(riverEvent));
    }

    /**
     * 删除河流事件
     */
    @PreAuthorize("@ss.hasPermi('riv:event:remove')")
    @Log(title = "河流事件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{eventIds}")
    public AjaxResult remove(@PathVariable Long[] eventIds)
    {
        return toAjax(riverEventService.deleteRiverEventByEventIds(eventIds));
    }
}
